<?php

class Gallery_Form_Photo extends Zend_Form {

	public function init() {
		$this->setMethod('post');
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		$defaultLang = key($locales);
		
		$subFormName = new Zend_Form_SubForm();
        $subFormName->removeDecorator('Fieldset');
        
        foreach($locales as $lang=>$value) {
			$name = new Zend_Form_Element_Text($lang);
			$name->setLabel(strtoupper($lang) . ' ' . _('Name:'));
			$name->setFilters(array('StringTrim','StripTags'));

			if($defaultLang == $lang) {
				$name->setRequired(true);
			}
			$subFormName->addElement($name);
        }
        
        $this->addSubForm($subFormName, 'name');
        
        $photo = $this->createElement('file', 'photo');
		$photo->setLabel(_('Select file:'));
		$photo->setDescription(_('Allow formats: jpeg, jpg, png, gif. Max file size 5Мб.'));
		$photo->setDestination(APPLICATION_PATH . "/../upload/media/pictures/gallery/original");
		$photo->addValidator('Count', false, 1);
		$photo->addValidator('Size', false, 5024000);
		$photo->addValidator('Extension', false, 'jpeg,jpg,png,gif');
        
        $published = $this->createElement('radio','published');
		$published->setLabel(_('Published:'));
		$published->setSeparator(' ');
		$published->addMultiOptions(array('1'=>_('Yes'),'0'=>_('No')));
		$published->setValue('1');
		$published->setRequired(true);
		
		$submit = $this->createElement('submit', 'submit');
		$submit->setLabel(_('Save'));
		
		$this->addElements(array($photo,$published,$submit));
	}
}